import useStore from "../../store";

export default upload=()=>{
    uni.chooseImage({
        count: 1, //默认9
        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album'], //从相册选择
        success: function (res) {
            console.log(JSON.stringify(res.tempFilePaths));
            uni.uploadFile({
                url:'http://localhost:8689/api/team/upload',
                filePath:res.tempFilePaths[0],
                name: 'file',
                header:{
                    "Authorization":uni.getStorageSync('Authorization'),
                    "content-type":"utf-8"
                },
                success: (uploadFileRes) => {
                    console.log(uploadFileRes.data);
                    const result=JSON.parse(uploadFileRes.data)
                    if(result.code===0){
                        uni.showToast({
                            title:'上传成功',
                            icon:'success',
                            
                            
                        })
                        useStore().user().updateAvartar(result.data)
                    }else{
                        uni.showToast({
                            title:'上传失败',
                            icon:'fail'


                        })
                    }
                }
            })
        }
    });
}